package com.qq.xqj.mapper;

import com.qq.xqj.modle.Car_info;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface Car_mapper {

    @Select("SELECT id,car_vars,car_names,car_versions,car_colors,car_addresss FROM car_in")
    List<Car_info> getCarInfo();

    @Select("<script> select * from car_in where"+
            "<if test='id != null'>id like concat('%',#{id},'%')" +
            "</if>"+
            "<if test='carVars != null'> car_vars like concat('%',#{carVars},'%')" +
            "</if>"+
            "<if test='carNames != null'> car_names like concat('%',#{carNames},'%')" +
            "</if>" +
            "<if test='carVersions != null'> car_versions like concat('%',#{carVersions},'%')" +
            "</if>"+
            "<if test='carColors != null'> car_colors like concat('%',#{carColors},'%')" +
            "</if>"+
            "<if test='carAddresss != null'> car_addresss sellingTime concat('%',#{carAddresss},'%')" +
            "</if></script>")
    public List<Car_info> selectCarByKey(Car_info car_info);

    @Select("SELECT car_totals FROM car_in WHERE car_names=#{carNames} and car_versions=#{carVersions} and car_colors=#{carColors}")
    int queryTotal(String carNames, String carVersions, String carColors);

    @Update("UPDATE car_in set car_totals=car_totals-1,car_outs=car_outs+1  WHERE car_names=#{carNames} and car_versions=#{carVersions} and car_colors=#{carColors}")
    int updateTotal(String carNames, String carVersions, String carColors);

    @Select(("SELECT car_names,car_versions,car_colors FROM car_in where id=#{id}"))
    Car_info queryCarById(int id);
}
